package com.codewsq.springboot.controller;

import com.codewsq.springboot.entity.User;
import com.codewsq.springboot.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = {"用户管理"})
public class UserController {

    @Autowired
    private UserService userService;

    @ApiOperation(value = "根据id查询用户信息", notes = "提示接口使用者注意事项", httpMethod = "GET")
    @GetMapping("/user/selectById")
    public User selectById(@RequestParam(value = "id") Integer id) {
        if (id == null) {
            return null;
        }
        return userService.selectByPrimaryKey(id);
    }

    @ApiOperation(value = "新增用户信息", notes = "注意有些属性不能为空", httpMethod = "POST")
    @PostMapping("/user/insert")
    public int insertUser(User user) {
        if (user == null) {
            return 0;
        }
        return userService.insertSelective(user);
    }
}
